home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / cir_3pnt.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  72 lines

  1. ; $Id: cir_3pnt.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. PRO cir_3pnt, x, y, r, x0, y0
  8.  
  9. ;+
  10. ; NAME:
  11. ;    CIR_3PNT
  12. ;
  13. ; PURPOSE:
  14. ;    This procedure returns the radius and center of a circle,
  15. ;    given 3 points on the circle. This is analogous to finding
  16. ;    the circumradius and circumcircle of a triangle; the center
  17. ;    of the circumcircle is the point at which the three perpendicular
  18. ;    bisectors of the triangle formed by the points meet.
  19. ;
  20. ; CATEGORY:
  21. ;    Analytical geometry.
  22. ;
  23. ; CALLING SEQUENCE:
  24. ;    CIR_3PNT, X, Y, R, X0, Y0
  25. ;
  26. ; INPUTS:
  27. ;    X: A three-element vector containing the X-coordinates of the points.
  28. ;    Y: A three-element vector containing the Y-coordinates of the points.
  29. ;
  30. ; OUTPUTS:
  31. ;    R: The radius of the circle. The procedure returns 0.0 if the points
  32. ;       are co-linear.
  33. ;    X0, Y0: The coordinates of the center of the circle. The procedure
  34. ;            returns 0.0 if the points are co-linear.
  35. ;
  36. ; PROCEDURE:
  37. ;    Derived from Glasser, ed.  Graphics Gems, Volume 1, Page 22.
  38. ;
  39. ; EXAMPLE:
  40. ;    X = [1.0, 2.0, 3.0]
  41. ;    Y = [1.0, 2.0, 1.0]
  42. ;    CIR_3PNT, X, Y, R, X0, Y0
  43. ;    Print, 'The radius is: ', R
  44. ;    Print, 'The center of the circle is at: ', X0, Y0
  45.     
  46. ; MODIFICATION HISTORY:
  47. ;     Written by:    DMS, RSI, Nov, 1992.
  48. ;-
  49.  
  50. x = double(x)
  51. y = double(y)
  52.  
  53. d1 = (x[2]-x[0]) * (x[1]-x[0]) + (y[2]-y[0]) * (y[1]-y[0])
  54. d2 = (x[2]-x[1]) * (x[0]-x[1]) + (y[2]-y[1]) * (y[0]-y[1])
  55. d3 = (x[0]-x[2]) * (x[1]-x[2]) + (y[0]-y[2]) * (y[1]-y[2])
  56.  
  57. c1 = d2 * d3
  58. c2 = d3 * d1
  59. c3 = d1 * d2
  60. c = c1 + c2 + c3 + 0.0        ;Force to floating or dbl
  61. if abs(c lt 1e-14) then begin    ;Colinear?
  62.     r =  0.
  63.     x0 = 0.
  64.     y0 = 0.
  65.     return
  66.     endif
  67. r = sqrt((d1 + d2)*(d2 + d3) * (d3 + d1)/c)/2.
  68. v = [ c2 + c3, c3 + c1, c1 + c2 ]/(2.*c)
  69. x0 = total(v * x)
  70. y0 = total(v * y)
  71. end
  72.